草庐IT

JSON 到 TypeScript 类实例?

全部标签

javascript - 纯JS获取Json数组

我想在不使用JQuery的情况下从跨域获取JSON数组。跨域过来的数据是这样的:{"transactionid":"LBS_48550801","status":0,"countrylist":[{"id":1,"name":"France","latitude":37.00039,"longitude":35.31411,"extent":{"minlatitude":36.53888499,"minlongitude":34.76786904,"maxlatitude":38.37851496,"maxlongitude":36.40534884}},{"id":2,"name":

javascript - Angularjs $http.get 将 JSON 数据作为带有转义引号而不是 json 的字符串返回

这里有一个有趣的问题。我有返回JSON的Restful后端。当我通过浏览器访问api时,它会返回一个经过验证的带有json对象的json数组。[{"GUID_Auth":null,"Email_Address":"abc@aol,"Measure_Id":1,"Title":"Prop41"}]但是当我通过angularjs发出$http.get请求时,我取回了一个带有转义引号的字符串gotsuccess:"[{\"GUID_Auth\":null,\"Email_Address\":\"abc@aol\",\"Measure_Id\":1,\"Title\":\"Prop41\"}]

javascript - 如何使用 sigma.js 显示来自 JSON 对象的数据

我想读取图的节点/边信息(sigma.js)来自JSON变量。虽然使用外部JSON文件非常容易作为通过JSON解析器的输入,我找不到使用JSON对象的方法直接在JavaScript代码中定义。似乎存在一种名为“读取”的方法,但我无法获得它可以工作(来源:https://github.com/jacomyal/sigma.js/wiki/Graph-API)。有人可以给我提示吗?这是我想要的:data={"nodes":[{"id":"n0","label":"Anode","x":0,"y":0,"size":3},{"id":"n1","label":"Anothernode","x

javascript - 在json中插入javascript变量值

我有一个JSON变量,看起来像这样:{"events":[{"event_id":"1","event_name":"Breakfast"},{"event_id":"1","event_name":"CallingBob"}]};我有两个变量x=2;y=jam;我想在json中推送变量,这样x是event_id,y是event_name,这样我的json看起来像-{"events":[{"event_id":"1","event_name":"Breakfast"},{"event_id":"1","event_name":"CallingBob"},{"event_id":"2",

javascript - 我如何使用 gulp 在不同的文件中而不是在 javascript 文件中创建 Typescript sourcemaps?

我有一个使用gulp的项目。我想将typescript文件转换为javascript并拥有源map。这是我现在拥有的:varsourcemaps=require('gulp-sourcemaps');vartypescript=require('gulp-typescript');gulp.task('typescript',function(){gulp.src('app/**/*.ts').pipe(typescript()).pipe(sourcemaps.init()).pipe(sourcemaps.write()).pipe(gulp.dest('app'))});这部分有

typescript - `share()` 和 `publish().refCount()` 之间的区别

observable.publish().refCount()和observable.share()之间的实际区别是什么。我们不想使用share的场景示例是什么? 最佳答案 没有实际区别,如果您查看“observable.prototype.share”,您会发现它只是返回“source.publish().refCount()”。至于为什么要使用它,更多的问题是您需要对源开始广播时进行多少控制。由于refCount()将在第一次订阅时附加底层可观察对象,因此后续观察者很可能会错过在他们订阅之前传入的消息。例如:varsource=

javascript - typescript 重载类方法 - 相同的返回类型,不同的参数

我有一个typescript类:classContactModel{publicgetUsage(type:string):restangular.IElement{returnthis.getBase().one('usages',type);}publicgetUsage(customerId:number,type:string):restangular.IElement{returnthis.ModelFactory.createRequestMapper(ContactModel.options).one('customers',customerId).all('contac

javascript - 将 Angular 1.x 与 TypeScript 1.5 和 SystemJS 结合使用

我正在尝试将Angular1.x与TypeScript1.5.3和SystemJS结合使用。index.html页面设置为System.import('bootstrapper'),它应该启动。bootstrapper.ts被编译为bootstrapper.js并且只要它不使用Angular就可以正常工作(即只做一个console.log()正常工作)现在,我想导入并使用angular来引导它。我已经完成了jspminstallangular并且我还使用tsd安装了一些angular类型。在bootstrap.ts文件的顶部引用了类型。不幸的是,importangularfrom'an

javascript - 通过 npm 安装 d3.js 对 Angular 2 TypeScript 项目有什么好处吗?

TL;DR:d3.js应该通过npm安装,输入也应该如此。接受的答案有详细信息。当我写这个问题时,我是Angular的新手。npm流程是标准流程:用于tree-shaking、包管理、更新等我有一个Angular2项目(为简单起见,它是快速启动项目),我正在导入d3.js版本4。d3没有TypeScript定义,因为它只是javascript。在index.html中,我添加了库:在typescriptapp.component.ts中,我引用了d3.select()....它工作正常-画了一个圆圈:d3.select("body").append("svg").attr("width

javascript - 如何使用 Node 从 WebStorm 中的 JavaScript 堆栈跟踪导航到原始 TypeScript 文件?

我是TypeScript的新手。在Mac上,我使用WebStorm2016.2.4forNodewithTypeScript2.0。使用生成的映射交互式调试工作正常,但运行时堆栈跟踪链接指向JavaScript文件,而不是原始TypeScript文件。这是正常的和预期的吗?是否有我缺少的WebStorm功能可以将这些链接转换为原始TypeScript文件和行,或者这只是TypeScript开发人员必须忍受的? 最佳答案 我通过要求模块source-map-support/register使用TypeScript源文件行号获取堆栈跟踪